const Router = require('koa-router');
const tool = require("../../tools/tool");
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");

// 删除退货商品
router.post('/bill/delBackGoods', async ctx => {
    let user = ctx.user
    let tenantId = user.tenantId;
    let body = ctx.request.body
    try {
        let id = body.id;
        await db.models['goodsBack'].destroy({
            where: {
                tenantId,
                id
            }
        })
        let data = await db.query(`select a.id,a.price,b.name invName,b.spec,b.unit1 from goods_back a inner join v_goods b on a.invId=b.id and a.tenantId=${tenantId}`, { type: QueryTypes.SELECT });
        return ctx.suc('', data);
    } catch (e) {
        return ctx.err(e);
    }
})

module.exports = router;